package suites.deeplink {
	import suites.AbstractConfig;
	import suites.stub.ProcessorStub;

	import org.flexunit.asserts.assertEquals;
	import org.flexunit.asserts.fail;
	import org.splink.deepsplink.processor.IProcessor;

	/**
	 * @author Max Kugland
	 */
	public class ProcessorTest extends AbstractDeeplinkControllerTest {

		[Test]
		public function startup() : void {
			var gotoFnc : Function = function(id : String, params : Array): void {
				assertEquals(0, params.length);
				assertEquals(AbstractConfig.HOME, id);
			};
			
			var count : uint = 0;
			var processorFnc : Function = function(id : String, params : Array): void {
				assertEquals(0, params.length);
				assertEquals(AbstractConfig.HOME, id);				count++;
			};
			
			createCtrl(gotoFnc);
			_ctrl.addProcessor(new ProcessorStub(processorFnc));
			_ctrl.start();
			
			assertEquals(1, count);
			assertEquals(1, _ctrl.history.length);
		}

		[Test]
		public function multiGoto() : void {
			var count : uint = 0;
			var processorFnc : Function = function(id : String, params : Array): void {
				count++;
			};

			createCtrl();
			_ctrl.addProcessor(new ProcessorStub(processorFnc));
			_ctrl.start();
			
			for (var i : int = 1;i < pageCount;i++) {
				_ctrl.gotoPage(i.toString());
			}

			assertEquals(pageCount - 1, count);			assertEquals(pageCount - 1, _ctrl.history.length);
		}

		[Test]
		public function remove() : void {
			var processor : IProcessor = new ProcessorStub(function(pageId : String, pageParams : Array):void {
				fail("I should have been removed!");
			});
			
			createCtrl();
			_ctrl.addProcessor(processor);			_ctrl.removeProcessor(processor);
			_ctrl.start();
		}
	}
}